<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%@ include file="inc/taglibs.jsp" %>
<!DOCTYPE html>
<html lang="zh-cn">
<head>
    <%@ include file="inc/meta.jsp" %>
    <meta name="description" content="">
    <meta name="author" content="">
    <title>管理员管理</title>
    <%@ include file="inc/css.jsp" %>
</head>
<body>

<div id="posts" class="wrapper">

    <%@ include file="inc/nav.jsp" %>

    <div id="page-wrapper">
        <div class="row">
            <div class="col-lg-12">
                <h1 class="page-header">管理管理员</h1>
                <h4 style="margin-left: 10px;" id="showH">——新增管理员</h4>
            </div>
        </div>

        <div class="row">
            <div class="col-lg-12">
                <div class="panel panel-default">
                    <!-- /.panel-heading -->
                    <div class="panel-body">
                        <form id="infoForm" method="post" action="backend/admin/save" class="form-horizontal nice-validator n-default" role="form" novalidate="novalidate">
                            <input type="hidden" id="id" name="adminId" value="${admin.id}"/>

                            <div class="form-group">
                                <label class="col-sm-2 control-label">账号:</label>

                                <div class="col-sm-4">
                                    <input type="text" class="form-control" id="account" name="account" maxlength="20"
                                           data-rule="required" value="${admin.account}" placeholder="请输入账号"/>
                                </div>
                            </div>

                            <div class="form-group">
                                <label class="col-sm-2 control-label">密码:</label>

                                <div class="col-sm-4">
                                    <input type="password" class="form-control" id="password" name="password" maxlength="20"
                                           data-rule="required" value="${admin.password}" placeholder="请输入密码"/>
                                </div>
                            </div>

                            <div class="form-group">
                                <label class="col-sm-2 control-label">昵称:</label>

                                <div class="col-sm-4">
                                    <input type="text" class="form-control" id="nickName" name="nickName" maxlength="20"
                                           data-rule="required" value="${admin.nickname}" placeholder="请输入昵称"/>
                                </div>
                            </div>

                            <div class="form-group">
                                <label class="col-sm-2 control-label">手机号:</label>

                                <div class="col-sm-4">
                                    <input type="text" class="form-control" id="mobile" name="mobile" maxlength="11"
                                           data-rule="required" value="${admin.mobile}" placeholder="请输入手机号"/>
                                </div>
                            </div>

                            <div class="form-group">
                                <label class="col-sm-2 control-label">微信号:</label>

                                <div class="col-sm-4">
                                    <input type="text" class="form-control" id="wxNum" name="wxNum" maxlength="50"
                                           data-rule="required" value="${admin.wxNum}" placeholder="请输入微信号"/>
                                </div>
                            </div>

                            <div class="form-group">
                                <label class="col-sm-2 control-label">备注信息:</label>

                                <div class="col-sm-6">
                                    <textarea id="remark" name="remark" class="form-control" maxlength="200" style="resize: none" placeholder="请输入备注信息" cols="40" rows="8">${admin.remark}</textarea>
                                </div>
                            </div>

                            <div class="form-group">
                                <div class="col-sm-offset-2 col-sm-6" style="text-align: center">
                                    <button type="button" class="btn btn-primary" onclick="admin.fn.subInfo()">确定添加</button>
                                    <button type="button" class="btn btn-primary" onclick="admin.fn.goBack()">返回</button>
                                </div>
                            </div>
                        </form>
                    </div>
                    <!-- /.panel-body -->

                </div>
                <!-- /.panel -->
            </div>
        </div>

    </div>
    <!-- /#page-wrapper -->

</div>
<!-- /#wrapper -->

<%@ include file="inc/footer.jsp" %>

</body>

<script type="text/javascript">
    var admin = {
        v: {
            id: "admin",
            list: [],
            dTable: null
        },
        fn: {
            init: function () {
                $.ajaxSetup({
                    async: false
                });

                if ($("#id").val() != "") {
                    $("#showH").text("——编辑管理人员");
                }
            },
            checkData: function () {
                var flag = true;
                var account = $('#account').val();
                var nickName = $('#nickName').val();
                var mobile = $('#mobile').val();
                var password = $('#password').val();

                if (null == account || account == '') {
                    $leoman.notify('账号不能为空', "error");
                    flag = false;
                    return;
                }

                if (null == password || password == '') {
                    $leoman.notify('密码不能为空', "error");
                    flag = false;
                    return;
                }

                if (null == nickName || nickName == '') {
                    $leoman.notify('昵称不能为空', "error");
                    flag = false;
                    return;
                }

                if (null == mobile || mobile == '') {
                    $leoman.notify('手机号不能为空', "error");
                    flag = false;
                    return;
                }

                return flag;
            },
            subInfo: function () {
                // 所有的验证通过后，执行新增操作
                if (admin.fn.checkData()) {
                    $("#infoForm").ajaxSubmit({
                        url: _basePath + "backend/admin/save",
                        dataType: "json",
                        success: function (data) {
                            if (data == 1) {
                                window.location.href = _basePath + "backend/admin/index";
                            } else if (data == -1) {
                                $leoman.notify("账号重复，请重新填写账号", "error");
                            } else if (data == -2) {
                                $leoman.notify("手机号重复，请重新填写手机号", "error");
                            } else {
                                $leoman.notify("操作失败", "error");
                            }
                        }
                    });
                }
            },
            goBack: function () {
                window.location.href = "backend/admin/index";
            }
        }
    }

    $(document).ready(function () {
        admin.fn.init();
    });

</script>

</html>